import { GButton } from "../../../../com/mui/controls/GButton";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { Global } from "../../../../com/gengine/global/Global";
import { _maxNum } from "../../../../this/_maxNum";
type int = number;
//class NumInput
    
    export  class NumInput /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        public set maxNum(arg1: int)
        {
            this._maxNum = arg1;
            this._currnetNum = this._maxNum;
            this._numTxt.text = this._currnetNum.toString();
            return;
        }

        public get currentNum(): int
        {
            return this._currnetNum;
        }

        public set currentNum(arg1: int)
        {
            this.setInRange(arg1);
            return;
        }

        public get minNum(): int
        {
            return this._minNum;
        }

        public set minNum(arg1: int)
        {
            this._minNum = arg1;
            this._currnetNum = arg1;
            this._numTxt.text = this._currnetNum.toString();
            return;
        }

        public set stepNumber(arg1: int)
        {
            this._stepNumber = arg1 <= 1 ? 1 : arg1;
            return;
        }

        public setStyleName(arg1: string): void
        {
            if (arg1 == "PageButton") 
            {
                this._addBtn.styleName = "NextPageButton";
                this._addBtn.width = 21;
                this._addBtn.height = 20;
                this._addBtn.drawNow();
                this._subBtn.styleName = "PrevPageButton";
                this._subBtn.width = 21;
                this._subBtn.height = 20;
                this._subBtn.drawNow();
            }
            return;
        }

        public setMaxNum(arg1: int): void
        {
            this._maxNum = arg1;
            return;
        }

        public /* override */ set width(arg1: number)
        {
            this._numTxt.width = arg1 - this._subBtn.width - this._addBtn.width - 10;
            this.onResize();
            return;
        }

        public /* override */ set height(arg1: number)
        {
            this._numTxt.height = arg1;
            this.onResize();
            return;
        }

        public onResize(): void
        {
            this._subBtn.y = (this._numTxt.height - this._subBtn.height) / 2;
            this._addBtn.x = this._subBtn.width + this._numTxt.width + 10;
            this._addBtn.y = (this._numTxt.height - this._subBtn.height) / 2;
            return;
        }

        public set editable(arg1: Boolean)
        {
            this._editable = arg1;
            this._subBtn.enabled = this._editable;
            this._numTxt.editable = this._editable;
            this._addBtn.enabled = this._editable;
            return;
        }

        public get editable(): Boolean
        {
            return this._editable;
        }

        /* internal  */init(): void
        {
            this._subBtn = new GButton();
            this._subBtn.width = 18;
            this._subBtn.height = 18;
            this._subBtn.label = "";
            this._subBtn.styleName = "SubBtn";
            this._subBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onSubBtnClickHandler);
            this._subBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onSubBtnMouseDownHandler);
            this._subBtn.drawNow();
            addChild(this._subBtn);
            this._numTxt = new GTextInput();
            this._numTxt.x = 23;
            this._numTxt.width = 40;
            this._numTxt.height = 18;
            this._numTxt.restrict = "0-9";
            this._numTxt.text = "1";
            this._numTxt.styleName = "GTextInput";
            this._numTxt.addEventListener(flash.events.Event.CHANGE, this.onNumChangeHandler);
            this._numTxt.drawNow();
            addChild(this._numTxt);
            this._addBtn = new GButton();
            this._addBtn.x = 68;
            this._addBtn.width = 18;
            this._addBtn.height = 18;
            this._addBtn.label = "";
            this._addBtn.styleName = "AddBtn";
            this._addBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onAddBtnClickHandler);
            this._addBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onAddBtnMouseDownHandler);
            this._addBtn.drawNow();
            addChild(this._addBtn);
            return;
        }

        /* internal  */onSubBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._stepNumber != 1) 
            {
                this._currnetNum = this._currnetNum - this._stepNumber;
            }
            else 
            {
                var loc1;
                var loc2=((loc1 = this)._currnetNum - 1);
                loc1._currnetNum = loc2;
            }
            this.setInRange(this._currnetNum);
            return;
        }

        /* internal  */onSubBtnMouseDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._isSubDown = true;
            addEventListener(flash.events.Event.ENTER_FRAME, this.onEnterframeHandler);
            Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onRemoveEnterframe);
            return;
        }

        /* internal  */onNumChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.setInRange(parseInt(this._numTxt.text));
            return;
        }

        /* internal  */setInRange(arg1: int): void
        {
            arg1 = arg1 < this._maxNum ? arg1 : _maxNum;
            arg1 = arg1 < this._minNum ? this._minNum : arg1;
            this._currnetNum = arg1;
            this._numTxt.text = this._currnetNum.toString();
            this.dispatchEvent(new Object /* flash.events.Event */(flash.events.Event.CHANGE));
            return;
        }

        /* internal  */onAddBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._stepNumber != 1) 
            {
                this._currnetNum = this._currnetNum + this._stepNumber;
            }
            else 
            {
                var loc1;
                var loc2=((loc1 = this)._currnetNum + 1);
                loc1._currnetNum = loc2;
            }
            this.setInRange(this._currnetNum);
            return;
        }

        /* internal  */onAddBtnMouseDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._isAddDown = true;
            addEventListener(flash.events.Event.ENTER_FRAME, this.onEnterframeHandler);
            Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onRemoveEnterframe);
            return;
        }

        /* internal  */onRemoveEnterframe(arg1: Object /* flash.events.Event */): void
        {
            this._isAddDown = false;
            this._isSubDown = false;
            this._count = 0;
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onRemoveEnterframe);
            removeEventListener(flash.events.Event.ENTER_FRAME, this.onEnterframeHandler);
            return;
        }

        /* internal  */onEnterframeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1;
            var loc2=((loc1 = this)._count + 1);
            loc1._count = loc2;
            if (this._count > 6) 
            {
                if (this._isAddDown) 
                {
                    if (this._stepNumber != 1) 
                    {
                        this._currnetNum = this._currnetNum + this._stepNumber;
                    }
                    else 
                    {
                        loc2 = ((loc1 = this)._currnetNum + 1);
                        loc1._currnetNum = loc2;
                    }
                    this.setInRange(this._currnetNum);
                }
                if (this._isSubDown) 
                {
                    if (this._stepNumber != 1) 
                    {
                        this._currnetNum = this._currnetNum - this._stepNumber;
                    }
                    else 
                    {
                        loc2 = ((loc1 = this)._currnetNum - 1);
                        loc1._currnetNum = loc2;
                    }
                    this.setInRange(this._currnetNum);
                }
            }
            return;
        }

        /* internal */ /* var */_numTxt: GTextInput;

        /* internal */ /* var */_minNum: int=1;

        /* internal */ /* var */_maxNum: int=2147483647;

        /* internal */ /* var */_currnetNum: int;

        /* internal */ /* var */_isSubDown: Boolean=false;

        /* internal */ /* var */_isAddDown: Boolean=false;

        /* internal */ /* var */_count: int=0;

        /* internal */ /* var */_stepNumber: int=1;

        /* internal */ /* var */_subBtn: GButton;

        /* internal */ /* var */_addBtn: GButton;

        /* internal */ /* var */_editable: Boolean;
    }
